<?php
declare (strict_types=1);

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

class SchoolCustomerSource extends Model
{
    use SoftDelete;

    protected $deleteTime = false;

    // 获取列表
    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');

        //按来源说明查找
        if ($source_info = input("source_info")) {
            $where[] = ["source_info", "like", "%" . $source_info . "%"];
        }

        $admin = session('admin');
        if ($admin['school_id'] > 0) {
            $where[] = ['school_id', '=', $admin['school_id']];
        }

        $list = self::with([
            'get_admin' => function($a) {
                $a->field('id,username');
            }
        ])->order('id', 'desc')->where($where)->paginate($limit);
        return ['code' => 0, 'data' => $list->items(), 'extend' => ['count' => $list->total(), 'limit' => $limit]];
    }

    public function getAdmin()
    {
        return $this->hasOne(AdminAdmin::class, 'id', 'admin_id');
    }
}
